package rxt.huiyi.com.rxterfit;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.OnClick;
import rxt.huiyi.com.rxterfit.component.DaggerMainComponent;
import rxt.huiyi.com.rxterfit.module.app.Url1Module;
import rxt.huiyi.com.rxterfit.presenter.Url1Presenter;
import rxt.huiyi.com.rxterfit.view.IShowData;
import rxt.huiyi.com.rxterfit.view.impl.URL1Respository;

public class MainActivity extends AppCompatActivity implements IShowData {

    @Inject
    public Url1Presenter presenter;
    @Inject
    public URL1Respository respository;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        //当系统版本为4.4或者4.4以上时可以使用沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        DaggerMainComponent.builder()
                .appComponent(RxJavaApplication.get(this).getRxAppComponent())
                .url1Module(new Url1Module(this,this))
                .uRL1Respository(new URL1Respository(this))
                .build().inject(this);
    }

    @OnClick(R.id.btn_url1)
    public void url_Test1(View source) {
        presenter.loadURl1Data(respository);
    }

    @Override
    public void showSuccessData(String data) {
        Toast.makeText(this,data,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showErrorData(String error) {
        Toast.makeText(this,error,Toast.LENGTH_SHORT).show();
    }

}
